// Programming_Scala/src/ch13/http-case-script.scala
sealed abstract class HttpMethod( val id: Int ) {
  def name = getClass getSimpleName
  override def toString = name
}

case object Connect extends HttpMethod( 0 )
case object Delete extends HttpMethod( 1 )
case object Get extends HttpMethod( 2 )
case object Head extends HttpMethod( 3 )
case object Options extends HttpMethod( 4 )
case object Post extends HttpMethod( 5 )
case object Put extends HttpMethod( 6 )
case object Trace extends HttpMethod( 7 )

def handle( method: HttpMethod ) = method match {
  case Connect => doPrintln( method )
  case Delete => doPrintln( method )
  case Get => doPrintln( method )
  case Head => doPrintln( method )
  case Options => doPrintln( method )
  case Post => doPrintln( method )
  case Put => doPrintln( method )
  case Trace => doPrintln( method )
}

def doPrintln( method: HttpMethod ): Unit = {
  println( method + ": " + method.id )
}

List( Connect, Delete, Get, Head, Options, Post, Put, Trace ) foreach {
  method => handle( method )
}